package com.liull.netty.protobuf;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @Author: liull
 * @Description: 使用Google protobuf
 * @Date: Created in 11:58 2020/9/26
 * @Modified By:
 */
public class ProtoServer {
    public static void main(String[] args) throws Exception {
        EventLoopGroup bossGroup = new NioEventLoopGroup(1);
        EventLoopGroup workerGroup = new NioEventLoopGroup();
        try {
            ServerBootstrap serverBootstrap = new ServerBootstrap();
            serverBootstrap.group(bossGroup, workerGroup)
                    .channel(NioServerSocketChannel.class)
                    .childHandler(new ProtoServerInitializer());
            serverBootstrap.bind(8888).addListener((future -> {
                if (future.isSuccess()) {
                    System.out.println("success!");
                } else {
                    System.err.println("Cannot start server, follows exception " + future.cause());
                }
            }))
                    .channel().closeFuture().sync();

        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }
}
